/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package futbol5;

import java.awt.BorderLayout;
import java.awt.Insets;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 *
 * @author Ivan
 */
public class BarraTemporizador extends JPanel implements PropertyChangeListener {

    private JProgressBar progressBar;
    private Contador task;
    private JTextArea taskOutput;

    BarraTemporizador() {
        super(new BorderLayout());

        progressBar = new JProgressBar(0, 60);
        progressBar.setValue(60);
        progressBar.setStringPainted(true);

        task = new Contador(60);
        task.addPropertyChangeListener(this);
        task.execute();

        taskOutput = new JTextArea(5, 20);
        taskOutput.setMargin(new Insets(5, 5, 5, 5));
        taskOutput.setEditable(false);


        JPanel panel = new JPanel();
        panel.add(progressBar);
        add(panel, BorderLayout.PAGE_START);
        add(new JScrollPane(taskOutput), BorderLayout.CENTER);
        setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        taskOutput.append("Arranca...");


    }

    public void propertyChange(PropertyChangeEvent evt) {

        taskOutput.append(evt.getPropertyName());
        if ("progress" == evt.getPropertyName()) {
            int nuevoValor = (Integer) evt.getNewValue();
            progressBar.setValue(nuevoValor);
            progressBar.setString(nuevoValor + "m");
            taskOutput.append(String.format(
                    "Completed %d%% of task.\n", task.getProgress()));

        }

    }
}
